package com.crt.uav.api.v1;

import com.crt.uav.annotation.SwaggerDocs;
import com.crt.uav.domain.UavTaskVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/api/v1")
@Tag(name = "无人机盘点接口", description = "提供给无人机盘点相关接口")
public class UavTaskEndPoint {

    private final UavRemoteService remoteService;

    public UavTaskEndPoint(UavRemoteService remoteService) {
        this.remoteService = remoteService;
    }

    @PostMapping("/insertTask")
    @Operation(summary = "无人机任务下发", requestBody = @io.swagger.v3.oas.annotations.parameters.RequestBody(
            description = "无人机任务信息",
            content = @Content(mediaType = "application/json", schema = @Schema(implementation = UavTaskVO.class))
    ))
    @SwaggerDocs.StandardResponses
    public String insertTask(@RequestBody UavTaskVO uavTaskVO) {
        return remoteService.post("/insertTask", uavTaskVO);
    }

    @PostMapping("/deleteTask")
    @Operation(summary = "无人机任务删除", requestBody = @io.swagger.v3.oas.annotations.parameters.RequestBody(
            description = "任务ID信息",
            content = @Content(mediaType = "application/json", schema = @Schema(example = "{\"task_id\": 1}"))
    ))
    @SwaggerDocs.StandardResponses
    public String deleteTask(@RequestBody Map<String, Object> params) {
        return remoteService.post("/deleteTask", params);
    }

    @PostMapping("/getTaskList")
    @Operation(summary = "查询任务列表", requestBody = @io.swagger.v3.oas.annotations.parameters.RequestBody(
            description = "分页参数",
            content = @Content(mediaType = "application/json", schema = @Schema(example = "{\"pagenum\": 1, \"pagesize\": 10}"))
    ))
    @SwaggerDocs.StandardResponses
    public String getTaskList(@RequestBody Map<String, Object> params) {
        return remoteService.post("/getTaskList", params);
    }

    @PostMapping("/getTaskDetail")
    @Operation(summary = "查询任务详情", requestBody = @io.swagger.v3.oas.annotations.parameters.RequestBody(
            description = "任务ID参数",
            content = @Content(mediaType = "application/json", schema = @Schema(example = "{\"task_id\": 1}"))
    ))
    @SwaggerDocs.StandardResponses
    public String getTaskDetail(@RequestBody Map<String, Object> params) {
        return remoteService.post("/getTaskDetail", params);
    }

    @PostMapping("/uavContinue")
    @Operation(summary = "无人机继续任务", requestBody = @io.swagger.v3.oas.annotations.parameters.RequestBody(
            description = "无人机序列号",
            content = @Content(mediaType = "application/json", schema = @Schema(example = "{\"uav_sn\": \"123456\"}"))
    ))
    @SwaggerDocs.StandardResponses
    public String uavContinue(@RequestBody String uavSn) {
        return remoteService.put("/uavContinue", uavSn);
    }
}
